package com.shanghaionstar.navi.search.history;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.onstar.cn.common.util.CommonUtil;
import com.shanghaionstar.R;
import com.shanghaionstar.navi.search.viewholder.NavSearchRecommendVH;

import java.util.List;
import java.util.Map;

/**
 * Created by zhaoyang on 2017/7/21.
 */

public class NavSearchRecommendAdapter extends RecyclerView.Adapter<NavSearchRecommendVH> {

    private List<Map<String, Object>> mDatas;
    private Context mContext;

    public NavSearchRecommendAdapter(Context context, List<Map<String, Object>> data) {
        mContext = context;
        mDatas = data;
    }

    public void setData(List<Map<String, Object>> list) {
        mDatas = list;
    }

    @Override
    public NavSearchRecommendVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.nav_search_item_grid_item, null);
        return new NavSearchRecommendVH(inflate);
    }

    @Override
    public void onBindViewHolder(NavSearchRecommendVH holder, int position) {
        holder.itemIcon.setImageResource((Integer) mDatas.get(position).get("grid_image"));
        holder.itemName.setText(mDatas.get(position).get("text_item_info").toString());
    }

    @Override
    public int getItemCount() {
        return CommonUtil.isNull(mDatas) ? 0 : mDatas.size();
    }
}
